package lcr;

import java.util.Arrays;

public class Test0406 {
}

class Solution0406_1 {
    public int[][] reconstructQueue(int[][] people) {
        int length = people.length;
        int[][] ans = new int[length][];
        Arrays.sort(people,(a,b)->{
            if (a[0] != b[0]) return a[0] - b[0];
            else return b[1] - a[1];
        });


        for (int[] person : people) {
            int count = person[1];
            for (int i = 0; i < length; i++) {
                if (ans[i]==null){
                    count--;
                    if (count<0){
                        ans[i]=person;
                        break;
                    }
                }
            }
        }
        return ans;
    }
}